package com.bwie.controller;

import com.bwie.config.FreemarkerUtil;
import com.bwie.config.R;
import com.bwie.pojo.Car;
import com.bwie.service.CarService;
import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

/**
 * @Auther:${涛}
 * @Date:2024/8/26 08:46
 * @Description: CatController
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/car")
public class CatController {


    @Autowired
    private CarService carService;

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @PostMapping("/Carlist")
    public R Carlist() throws TemplateException, IOException {
        List<Car> list = carService.list();
        return R.OK(list);
    }

    @RequestMapping("/freemarker")
    public R freemarker() throws TemplateException, IOException {



        List<Car> list = carService.list();

        FreemarkerUtil freemarkerUtil = new FreemarkerUtil();

        HashMap<String, Object> map = new HashMap<>();

        map.put("list", list);

        String outputFilePath = "D:\\test" + UUID.randomUUID().toString();

        freemarkerUtil.createHtml(map, "aa", outputFilePath);
        return R.OK();
    }


}


